Skip to content

Support weak definitions #4414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Support weak definitions #4414

wants to merge 3 commits into from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jun 26, 2025

When a symbol only has a weak definition, this definition will be picked. When a symbol has both a weak and a regular definition, the regular definition will be picked instead.

In the future the allocator shim may be replaced by weak definitions. This already adds support to simplify things in the future.

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 26, 2025

This has been extracted out of rust-lang/rust#134522.

@bjorn3 bjorn3 force-pushed the weak_defs branch 3 times, most recently from 5a433c4 to 2402b40 Compare June 27, 2025 10:27
Comment on lines 215 to 239
if let Some((instance, _, _)) = instance_and_crate {
if !matches!(tcx.def_kind(instance.def_id()), DefKind::Fn | DefKind::AssocFn) {
throw_ub_format!(
"attempt to call an exported symbol that is not defined as a function"
);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this logic can live here as well, but is there a specific reason you moved it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I recall.

@RalfJung
Copy link
Member

@rustbot author

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Jun 28, 2025
@jdonszelmann
Copy link
Contributor

what's the status of this one @bjorn3? (I expect just little time which is very fair <3)

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 6, 2025

Somehow I didn't notice there were outstanding review comments.

bjorn3 added 2 commits August 6, 2025 17:43
When a symbol only has a weak definition, this definition will be
picked. When a symbol has both a weak and a regular definition, the
regular definition will be picked instead.
@bjorn3 bjorn3 force-pushed the weak_defs branch 2 times, most recently from 59a946e to de4a356 Compare August 6, 2025 17:48
@bjorn3
Copy link
Member Author

bjorn3 commented Aug 6, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants